package com.zj.study.pojo.model;

import com.alibaba.fastjson.JSON;
import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 赵赳
 * @since 2021/12/14 10:06
 */
@RestController
public class TreeTypeTest {

  /**
   * 获取树形数据
   *
   * @return 树形数据
   */
  @GetMapping("/getTreeMap")
  public  String getTreeMap() {
    return JSON.toJSONString(getTreeMapValue());
  }


  public static  Map<Object, Map<Object,List<Object>>> getTreeMapValue() {
    SchoolInf schoolInf = new SchoolInf("学校信息汇总");
    School school_one = new School("school-one");
    School school_two = new School("school-two");
    Student Jack = new Student("Jack");
    Student Rose = new Student("Rose");
    Student Jon = new Student("Jon");
    Student Bob = new Student("Bob");
    Student Alisa = new Student("Alisa");

    // 树形结构体
    BeanTree tree = new BeanTree();
    // 根节点
    BeanTreeNode root = tree.addNode(null, schoolInf, "root");
    // 两个parent节点
    BeanTreeNode school_node1 = tree.addNode(root, school_one, "school");
    BeanTreeNode school_node2 = tree.addNode(root, school_two, "school");
    // 子节点
    tree.addNode(school_node1, Jack, "school");
    tree.addNode(school_node1, Rose, "school");
    tree.addNode(school_node1, Jon, "school");
    tree.addNode(school_node2, Bob, "school");
    tree.addNode(school_node2, Alisa, "school");
    return tree.toTreeMap1();
  }



  /*public static void main(String[] args) {
    SchoolInf schoolInf = new SchoolInf("2017-10-1XX省学校信息总汇");
    School school_one = new School("school-one");
    School school_two = new School("school-two");
    Student Jack = new Student("Jack");
    Student Rose = new Student("Rose");
    Student Jon = new Student("Jon");
    Student Bob = new Student("Bob");
    Student Alisa = new Student("Alisa");

    // 树形结构体
    BeanTree tree = new BeanTree();
    // 根节点
    BeanTreeNode root = tree.addNode(null, schoolInf, "root");
    // 两个parent节点
    BeanTreeNode school_node1 = tree.addNode(root, school_one, "school");
    BeanTreeNode school_node2 = tree.addNode(root, school_two, "school");
    // 子节点
    tree.addNode(school_node1, Jack, "root");
    tree.addNode(school_node1, Rose, "root");
    tree.addNode(school_node1, Jon, "root");
    tree.addNode(school_node2, Bob, "root");
    tree.addNode(school_node2, Alisa, "root");

    var parentBean = tree.getParentBean(Bob);
    System.out.println("parentBean = " + parentBean);

    var map = tree.toTreeMap1();
    System.out.println("map = " + map);

    var jsonString = JSON.toJSONString(map);
    System.out.println("jsonString = " + jsonString);
  }*/

}
